<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            操作者执行情况
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">开始时间</div>
                    <div class="aui-list-item-input" onclick="showTime();">
                        <input type="text" placeholder="选择时间" class="aui-input" id="scrapDate">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">结束时间</div>
                    <div class="aui-list-item-input" onclick="showTime2();">
                        <input type="text" placeholder="选择时间" class="aui-input" id="scrapDateEnd">
                    </div>
                </div>
            </li>
        </ul>
        </br>
        </br>
        <div class="aui-btn aui-btn-info aui-btn-block"
            style="width:80%;margin-left:10%;font-size: 30px;font-weight: bold;" onclick="goPage('CZZSG')">操作者上岗情况</div>
        </br>
        <div class="aui-btn aui-btn-info aui-btn-block"
            style="width:80%;margin-left:10%;font-size: 30px;font-weight: bold;" onclick="goPage('KBDJ')">开班点检情况</div>
        </br>
        <div class="aui-btn aui-btn-info aui-btn-block"
            style="width:80%;margin-left:10%;font-size: 30px;font-weight: bold;" onclick="goPage('SCJJB')">生产交接班情况</div>
        </br>
        <div class="aui-btn aui-btn-info aui-btn-block"
            style="width:80%;margin-left:10%;font-size: 30px;font-weight: bold;" onclick="goPage('KGGD')">开工工单情况</div>
        </br>
        <div class="aui-btn aui-btn-info aui-btn-block"
            style="width:80%;margin-left:10%;font-size: 30px;font-weight: bold;" onclick="goPage('SCBG')">生产报工情况</div>
        </br>
        <div class="aui-btn aui-btn-info aui-btn-block"
            style="width:80%;margin-left:10%;font-size: 30px;font-weight: bold;" onclick="goPage('RYLG')">人员离岗情况</div>
        </br>

    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //日期
    var scrapDate = "";
    var scrapDateEnd = "";
    //初始化
    apiready = function () {
        //获取当前日期
        crateDate()
    }
    //获取当前日期
    function crateDate() {
        var date = new Date(); // 当前时间
        var currentTime = date.getTime(); // 当前时间的时间戳
        console.log(currentTime)
        // 获取当天早上 8 点的时间
        var today = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 8, 0, 0).getTime();
        console.log(today)
        // 获取次日早上 8 点的时间
        var tomorrow = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1, 8, 0, 0).getTime();
        console.log(tomorrow)
        if (currentTime >= today && currentTime < tomorrow) {
            // 当前时间在当天早上 8 点到次日早上 8 点之间
            var startDate = new Date(); // 当前时间
            var endDate = new Date();
            endDate.setDate(endDate.getDate() + 1); // 加一天

            // 格式化开始时间
            var startYear = startDate.getFullYear();
            var startMonth = startDate.getMonth() + 1 < 10 ? "0" + (startDate.getMonth() + 1) : startDate.getMonth() + 1;
            var startDay = startDate.getDate() < 10 ? "0" + startDate.getDate() : startDate.getDate();
            var startTime = startYear + "-" + startMonth + "-" + startDay + " 08:00";

            // 格式化结束时间
            var endYear = endDate.getFullYear();
            var endMonth = endDate.getMonth() + 1 < 10 ? "0" + (endDate.getMonth() + 1) : endDate.getMonth() + 1;
            var endDay = endDate.getDate() < 10 ? "0" + endDate.getDate() : endDate.getDate();
            var endTime = endYear + "-" + endMonth + "-" + endDay + " 08:00";

            $("#scrapDate").val(startTime); // 设置开始时间
            $("#scrapDateEnd").val(endTime); // 设置结束时间
        } else {
            // 默认逻辑
            date.setDate(date.getDate() - 1); // 获取昨天的日期
            var year = date.getFullYear();
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            $("#scrapDate").val(year + "-" + month + "-" + day + " 08:00");
            date.setDate(date.getDate() + 1); // 获取当天的日期
            var yearNext = date.getFullYear();
            var monthNext = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var dayNext = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            $("#scrapDateEnd").val(yearNext + "-" + monthNext + "-" + dayNext + " 08:00");
        }

    }

    function showTime() {
        var moduleTimer = api.require('moduleTimer');
        moduleTimer.showTimer({
            startTime: '2000-01-01 00:00',//可选择的起始时间
            endTime: '2099-12-31 23:59',//可选择的结束时间
            timeFormat: 'yyyy-MM-dd HH:mm',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
            selColor: '#079962'//选中的颜色值
        }, function (ret, err) {
            var actualBeginDate = ret;
            var text = document.getElementById("scrapDate");
            text.value = actualBeginDate;
        });
    }

    function showTime2() {
        var moduleTimer = api.require('moduleTimer');
        moduleTimer.showTimer({
            startTime: '2000-01-01 00:00',//可选择的起始时间
            endTime: '2099-12-31 23:59',//可选择的结束时间
            timeFormat: 'yyyy-MM-dd HH:mm',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
            selColor: '#079962'//选中的颜色值
        }, function (ret, err) {
            var actualBeginDate = ret;
            var text = document.getElementById("scrapDateEnd");
            text.value = actualBeginDate;
        });
    }

    //跳转页面
    function goPage(flag) {
        if (flag == "CZZSG") {
            //操作者上岗情况
            name = "operatorPerformance_czzsg";
        } else if (flag == "KBDJ") {
            //开班点检情况
            name = "operatorPerformance_kbdj";
        }
        else if (flag == "SCJJB") {
            //生产交接班情况
            name = "operatorPerformance_scjjb";
        }
        else if (flag == "KGGD") {
            //开工工单情况
            name = "operatorPerformance_kggd";
        }
        else if (flag == "SCBG") {
            //生产报工情况
            name = "operatorPerformance_scbg";
        }
        else if (flag == "RYLG") {
            //人员离岗情况
            name = "operatorPerformance_rylg";
        }
        scrapDate = $("#scrapDate").val()
        scrapDateEnd = $("#scrapDateEnd").val()
        //打开页面
        api.openWin({
            name: name,
            url: name + '.html',
            pageParam: {
                name: "operatorPerformance",
                chkBillType: 2,
                flag: flag,
                scrapDate: scrapDate,
                scrapDateEnd: scrapDateEnd
            }
        });
    }

    //时间选择器
    function timePicker() {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择时间'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#scrapDate").val(date);
            }
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>